﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model YTCMS.Domain.Entities.products
@using YTCMS.Core;
<link href="/Content/uploadify.css" rel="stylesheet" />
<script src="/Scripts/jquery.uploadify.js"></script>
<style type="text/css">
    .uploadify-button {
        /*background: url("/Content/img/upload1.png");*/
        border: 0;
        border-radius: 0;
        display: inline-block;
        margin-left: 1px;
        position: absolute;
        top: 0;
        left: 0;
    }

    .makefriend .tag .btn {
        width: 100%;
        height: 20px;
        border-radius: 0px;
        font-size: 12px;
        background-color: #fb9337;
        color: #fff;
        box-shadow: -2px 2px rgba(158, 153, 153, 0.47);
        margin: 0 10px 0 0;
        padding: 3px 6px;
        text-align: center;
        display: inline;
        white-space: normal;
    }

    .makefriend .btn {
        width: 100px;
        height: 40px;
        background-color: #d93467;
        border-radius: 8px;
        font-size: 18px;
        display: inline-block;
        box-shadow: -1px 1px #ddd;
    }

        .makefriend .btn:hover {
            background-color: #d93467;
        }
    /*.makefriend .modal-dialog{
      width: 320px;
      margin: 350px auto 0;
      text-align: center;
    }*/
    .makefriend .modal-content {
        width: 320px;
        padding: 30px 40px 20px;
        margin: 10% auto 0;
        text-align: center;
    }

    .makefriend .hislabel {
        width: 100%;
        /*text-align: left;*/
        font-size: 12px;
    }

    .makefriend .level {
        text-align: center;
    }

    .expdiv {
        padding: 4px;
        width: 80px;
        border: 1px solid #c8c8c8;
        float: left;
    }

    .expbtn {
        position: absolute;
        z-index: 2;
        margin: -15px 0px 0px 50px;
    }

        .expbtn a {
            display: block;
            width: 32px;
            height: 32px;
            background: #fff;
            background: url(/Content/img/Stop.png);
        }

    /*.expbtn a:hover {
        background: url(../images/btn_playbg.gif) left -16px;
    }*/
</style>
<script charset="utf-8" src="/Content/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/Content/kindeditor/lang/zh_CN.js"></script>
<div class="page-content">
    <div class="page-header">
        <h1>
            商品管理
            <small>
                <i class="icon-double-angle-right"></i>
                发布商品
            </small>
        </h1>
    </div><!-- /.page-header -->

    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal" id="form1" action="/product/edit" method="post">
                @Html.ValidationSummary(true)
                <div class="tabbable">
                    <ul class="nav nav-tabs" id="myTab">
                        <li class="active">
                            <a data-toggle="tab" href="#home">
                                <i class="green icon-home bigger-110"></i>
                                线路基本信息
                            </a>
                        </li>

                        <li class="" id="li_custom">
                            <a data-toggle="tab" href="#profile">
                                线路特色
                                <span class="badge badge-danger">2</span>
                            </a>
                        </li>

                        <li class="dropdown" id="li_Hod">
                            <a data-toggle="tab" href="#Hod">
                                行程安排
                                <span class="badge badge-danger">2</span>
                            </a>


                        </li>
                    </ul>

                    <div class="tab-content">
                        <div id="home" class="tab-pane active">
                            <div class="widget-box">
                                <div class="widget-header">
                                    <div class="widget-toolbar">
                                        <a href="#" data-action="collapse">
                                            <i class="icon-chevron-up"></i>
                                        </a>

                                        <a href="#" data-action="close">
                                            <i class="icon-remove"></i>
                                        </a>
                                    </div>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main">
                                        <div>
                                            <label for="form-field-8">商品名称</label>
                                            @Html.TextBoxFor(s => s.Name, new { @class = "form-control required" })
                                            @Html.ValidationMessageFor(s => s.Name)
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品分类</label>
                                            <div class="row">
                                                <div class="col-md-3">
                                                    @Html.DropDownList("ddl1", Admin.Common.YTDDL.Category(s => s.Pid.Value == 0 && s.Level == 1 && s.State == (int)CommonState.正常, true), new { @class = "form-control", @onchange = "ddlonchange('ddl2','/Util/CategoryDDL',{pid:this.value},function(){$('#ddl3').empty().append('<option value=\"\">请选择</option>'); $('#CategoryId').val($('#ddl1').val())})" })
                                                </div>
                                                <div class="col-md-3">
                                                    <select class="form-control" id="ddl2" name="ddl2" onchange="javascript: $('#CategoryId').val(this.value)">
                                                        <option value="">请选择</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品卖价(￥)</label>
                                            @Html.TextBoxFor(s => s.Price, new { @class = "form-control required number" })
                                            @Html.ValidationMessageFor(s => s.Price)
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品原价(￥)</label>
                                            @Html.TextBoxFor(s => s.OldPrice, new { @class = "form-control required number" })
                                            @Html.ValidationMessageFor(s => s.OldPrice)
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品标签</label>
                                            @Html.DropDownListFor(s => s.Tag, Admin.Common.YTDDL.ProductTags(true), new { @class = "form-control" })
                                        </div>
                                        <div>
                                            <label for="form-field-8">库存</label>
                                            @Html.TextBoxFor(s => s.Stock, new { @class = "form-control required digits " })
                                            @Html.ValidationMessageFor(s => s.Stock)
                                        </div>
                                        <div>
                                            <label for="form-field-8">排序</label>
                                            @Html.TextBoxFor(s => s.Sort, new { @class = "form-control required digits" })
                                            @Html.ValidationMessageFor(s => s.Sort)
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品主图片</label>
                                            <input type="file" name="file_upload" id="file_upload" class="form-control" maxlength="200" />
                                            <div class="row">
                                                <div>
                                                    @*<div id="divimg">
                                                        <img src='@Model.Image' height='100px' width='80px' />
                                                    </div>*@
                                                    <div id="divimg">
                                                        @{
                                                            var pi = ViewData["pimgs"] as string[];
                                                            string imageurls = "";
                                                            if (pi.Any())
                                                            {
                                                                foreach (var item in pi)
                                                                {
                                                                    <div class='expdiv'><div class='expbtn'><a href='javascript:void(0)' onclick='imgclose(this)' value='@item'></a></div><img src='@item' height='100px' width='80px' /></div>
                                                                    imageurls += item + ",";
                                                                }
                                                            }
                                                            @Html.Hidden("hidimg", imageurls != "" ? imageurls.Remove(imageurls.Length - 1, 1) : "");
                                                        }
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div>
                                            <label for="form-field-8">订购（联系）电话</label>
                                            @Html.TextBoxFor(s => s.Phone, new { @class = "form-control required" })
                                            @Html.ValidationMessageFor(s => s.Sort)
                                        </div>
                                        <div>
                                            <label for="form-field-8">订购QQ</label>
                                            @Html.TextBoxFor(s => s.QQ, new { @class = "form-control required" })
                                            @Html.ValidationMessageFor(s => s.QQ)
                                        </div>
                                        <div>
                                            <label for="form-field-8">最近期团</label>
                                            @Html.TextBoxFor(s => s.Latest, new { @class = "form-control required" })
                                            @Html.ValidationMessageFor(s => s.Latest)
                                        </div>
                                        <div>
                                            <label for="form-field-8">付款方式</label>
                                            @Html.DropDownListFor(s => s.PayTpeId, Admin.Common.YTDDL.PayType(true), new { @class = "form-control" })
                                            @Html.ValidationMessageFor(s => s.PayTpeId)
                                        </div>
                                        <div>
                                            <label for="form-field-8">住宿</label>
                                            @Html.DropDownListFor(s => s.Hotel, Admin.Common.YTDDL.Hotel(true), new { @class = "form-control" })
                                            @Html.ValidationMessageFor(s => s.Hotel)
                                        </div>
                                        <div>
                                            <label for="form-field-8">交通工具</label>
                                            @Html.DropDownListFor(s => s.Vehicle, Admin.Common.YTDDL.Vehicle(true), new { @class = "form-control" })
                                            @Html.ValidationMessageFor(s => s.Vehicle)
                                        </div>
                                        <div>
                                            <label for="form-field-8">是否推荐</label>
                                            @Html.RadioButtonFor(s => s.IsPush, 1) 是
                                            @Html.RadioButtonFor(s => s.IsPush, 0) 否
                                        </div>
                                        <div>
                                            <label for="form-field-8">状态</label>
                                            @Html.DropDownListFor(s => s.State, Admin.Common.YTDDL.CommonState(true), new { @class = "form-control" })
                                            @Html.ValidationMessageFor(s => s.State)
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品介绍说明</label>
                                            @Html.TextAreaFor(s => s.Introduce, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品描述(PC)</label>
                                            @Html.TextAreaFor(s => s.Remark, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                        </div>
                                        <div>
                                            <label for="form-field-8">商品描述(WAP)</label>
                                            @Html.TextAreaFor(s => s.WapRemark, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="profile" class="tab-pane">
                            <div class="widget-box">
                                <div class="widget-main">
                                    <div>
                                        <label for="form-field-8">线路特色（PC）:</label>
                                        @Html.TextAreaFor(s => s.Feature, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>
                                    <div>
                                        <label for="form-field-8">线路特色(WAP):</label>
                                        @Html.TextAreaFor(s => s.WapFeature, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>

                                    <div>
                                        <label for="form-field-8">费用协议（PC）:</label>
                                        @Html.TextAreaFor(s => s.Agreement, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>
                                    <div>
                                        <label for="form-field-8">费用协议（WAP）:</label>
                                        @Html.TextAreaFor(s => s.WapAgreement, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="Hod" class="tab-pane">
                            <div class="widget-box">
                                <div class="widget-main">
                                    <div>
                                        <label for="form-field-8">行程天数:</label>
                                        @Html.TextBoxFor(s => s.HodometerDay, new { @class = "form-control number" })
                                    </div>
                                    <div>
                                        <label for="form-field-8">行程安排（PC）:</label>
                                        @Html.TextAreaFor(s => s.Hodometer, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>
                                    <div>
                                        <label for="form-field-8">行程安排（WAP）:</label>
                                        @Html.TextAreaFor(s => s.WapHodometer, new { @class = "form-control", @style = "margin: 0px; width: 100%; height: 85px;" })
                                    </div>
                                    <div>
                                        <button class="btn btn-info" id="btnSave" type="button" style="margin:10px 0 10px 0;">
                                            <i class="icon-ok bigger-110"></i>
                                            保存
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        @Html.HiddenFor(s=>s.Image)
                        @Html.Hidden("CategoryId", Model.CategoryId)
                        @Html.HiddenFor(s => s.Id)
                        @Html.HiddenFor(s => s.CreateTime)
                        @Html.HiddenFor(s => s.strcategory)
                        @Html.HiddenFor(s => s.uid)
                    </div>
                </div>
            </form>



        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
<script>
    var imgs = new Array();
    $(function () {
        imgs = $("#hidimg").val().split(',')
        $("#btnSave").click(function () {
            var b = jQuery("#form1").valid();
            if (b) {
                $("#hidimg").val(imgs.toString())
                $("#form1").submit();
                //$("#form1").submit();
                //$.post("/Module/add", $("#form1").serialize(), function (data) {
                //    if (data.d) {
                //        jAlert("新增成功", "提示", function () {
                //            location.href = "/Module/index";
                //        })
                //    }
                //    else {
                //        jAlert(data.msg, "提示");
                //    }
                //})
            }
        });

        var editor, editor1, editor2, editor3, editor4, editor5, editor6, editor7;
        KindEditor.ready(function (K) {
            editor = K.create('#Remark', {
                uploadJson: '/Util/KindEditorHandlerFile',
                afterBlur: function () { editor.sync(); },
                allowFileManager: true
            });
            editor4 = K.create('#WapRemark', {
                uploadJson: '/Util/KindEditorHandlerFile',
                afterBlur: function () { editor.sync(); },
                allowFileManager: true
            });
        });
        $("#li_custom").click(function () {
            KindEditor.ready(function (K) {
                editor1 = K.create('#Feature', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor1.sync(); },
                    allowFileManager: true
                });

                editor2 = K.create('#Agreement', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor2.sync(); },
                    allowFileManager: true
                });
                editor5 = K.create('#WapFeature', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor2.sync(); },
                    allowFileManager: true
                });
                editor6 = K.create('#WapAgreement', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor2.sync(); },
                    allowFileManager: true
                });
            });

        });
        $("#li_Hod").click(function () {
            KindEditor.ready(function (K) {
                editor3 = K.create('#Hodometer', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor3.sync(); },
                    allowFileManager: true
                });
                editor7 = K.create('#WapHodometer', {
                    uploadJson: '/Util/KindEditorHandlerFile',
                    afterBlur: function () { editor2.sync(); },
                    allowFileManager: true
                });
            });
        });

    })

    setTimeout(function () {
        jQuery('#file_upload').uploadify({
            'swf': '/Scripts/uploadify.swf',
            'uploader': '/Util/ImgUploadByProducts',
            'fileTypeExts': '*.gif; *.jpg; *.png; *.bmp; *.jpeg',
            'multi': false,
            'fileObjName': 'filedata',
            'wmode': 'transparent',
            'fileSizeLimit': '2MB',
            'onSelectError': function (file, errorCode, errorMsg) {
                jAlert("文件大小超出系统限制的", "提示")
            },
            'onFallback': function () {
                jAlert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。", "提示");
            },
            onUploadSuccess: function (file, data, respone) {
                $("#divimg").append("<div class='expdiv'><div class='expbtn'><a href='javascript:void(0)' onclick='imgclose(this)' value='" + data + "'></a></div><img src='" + data + "' height='100px' width='80px' /></div>")

                //$("#Image").val(data)
                imgs.push(data);
            }
        });
    }, 10);

    function imgclose(obj) {
        $(obj).parents(".expdiv").remove();
        imgs.remove($(obj).attr("value"));
    }
</script>